package dao;

import java.util.LinkedList;
import java.util.List;

import entities.Single;

public class SingleDAO 
{

	private static final SingleDAO instance = new SingleDAO();
	private List<Single> singles;
	
	private SingleDAO(){
		singles = new LinkedList<Single>();
		Single temp = null;
		
		//temp = Single.newInstance("admin", "admin@lol.com", "Jaime", "Vazquez", "admin");
		//singles.add(temp);
	}
	
	public static SingleDAO getInstance() {
		return instance;
	}

	public synchronized Single findSingle(Long a_id) {
		Single result = null;
		for (Single s : singles){
			if (s.getA_id().equals(a_id)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addSingle(Single obj) throws RecordDuplicateException{
		if (findSingle(obj.getA_id()) != null){
			throw new RecordDuplicateException("Customer with id: " + obj.getA_id() + " is already in the db.");
		}
		else {
			singles.add(obj);
		}
	}
}
